class AddEmployeeContract < Mutations::Command
  include Wisper::Publisher

  required do
    integer :employee_id
    date    :valid_end
    date    :valid_from
    integer :contract_type_id
    string  :number
  end
  
  def execute
    unless employee = Employee.find_by_id(employee_id)
      add_error(:employee_id, :employee_not_exist, '员工不存在')
      return
    end

    employee_contract = Contract.new inputs
    if employee_contract.save
      return employee_contract
    else
      employee_contract.errors.each do |key, value|
        add_error(key, key, value)
      end
    end
  end
end